#include "EnemyToken.h"

#include "../ScriptingSystem/InitEnemyScript.h"
#include <assert.h>

EnemyToken::EnemyToken(void)
{
	m_nTokenID = Enemy_Token;

	m_nHealth = 0;
	m_nDamage = 0;
	m_nEnemyID = -1;
	m_fSpeed = 0.0f;
	m_fJumpSpeed = 0.0f;
	m_fAttackTimer = 0.0f;
}


EnemyToken::~EnemyToken(void)
{
}

void EnemyToken::Update( float fElapsedTime )
{
	BaseToken::Update( fElapsedTime );
}

void EnemyToken::Render( void )
{
	BaseToken::Render();
}

RECT EnemyToken::GetRect( void ) const
{
	return BaseToken::GetRect();
}

bool EnemyToken::CheckCollision( IBaseToken* pOther )
{
	if( BaseToken::CheckCollision( pOther ) == true )
	{
		SetVelX( -GetVelX() );
		SetVelY( -GetVelY() );
		return true;
	}

	return false;
}

void EnemyToken::InitFromScript( CScript* pScript, int nID )
{
	assert( dynamic_cast<CInitEnemyScript*>(pScript) != nullptr && "EnemyToken::InitFromScript - the script is not for the enemy" );

	// local variables to take in the data from the script that the EnemyToken class can't access
	float fX, fY;
	int nWidth, nHeight;

	switch( nID )
	{
	case Crawler:
		{

		}
		break;
	case Ground:
		{
			dynamic_cast<CInitEnemyScript*>(pScript)->CallInitGroundEnemy( fX, fY, nWidth, nHeight, m_nHealth, m_nDamage, m_nEnemyID, m_fSpeed, m_fJumpSpeed );
		}
		break;
	case Air:
		{
			dynamic_cast<CInitEnemyScript*>(pScript)->CallInitAirEnemy( fX, fY, nWidth, nHeight, m_nHealth, m_nDamage, m_nEnemyID, m_fSpeed );
		}
		break;
	case Mage:
		{
			dynamic_cast<CInitEnemyScript*>(pScript)->CallInitMageEnemy( fX, fY, nWidth, nHeight, m_nHealth, m_nDamage, m_nEnemyID, m_fSpeed, m_fJumpSpeed );
		}
		break;
	case Sentinel:
		{
			dynamic_cast<CInitEnemyScript*>(pScript)->CallInitSentinelEnemy( fX, fY, nWidth, nHeight, m_nHealth, m_nDamage, m_nEnemyID, m_fSpeed, m_fJumpSpeed );
		}
		break;
	}

	// Use the local variables to assign the data to the BaseToken data memmbers
	SetPosX( fX );
	SetPosY( fY );
	SetWidth( nWidth );
	SetHeight( nHeight );
}